package com.mentalhealthplatform.studentV3.dto;

import com.mentalhealthplatform.global.rbac.dto.normal.RoleDTO;
import com.mentalhealthplatform.global.rbac.model.User;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * @author Pear
 */
@Getter
@Setter
@NoArgsConstructor
public class UserDTOV3 {

    // Getters 和 Setters

    private UUID id;
    private String username;
    private boolean status;
    private Set<RoleDTO> roles;
    private String nickname;
    private String department;
    private String phone;
    private String password;

    public UserDTOV3(User user) {
        this.id = user.getId();
        this.username = user.getUsername();
        this.status = user.isStatus();
        this.roles = user.getRoles().stream()
               .map(RoleDTO::fromRole)
               .collect(Collectors.toSet());
        this.phone = user.getPhone();
        this.password = user.getPassword();
    }

    // 静态方法将 User 转换为 UserDTOV3
    public static UserDTOV3 fromUser(User user) {
        UserDTOV3 userDTO = new UserDTOV3(user);
        userDTO.setId(user.getId());
        userDTO.setUsername(user.getUsername());
        userDTO.setStatus(user.isStatus());

        // 将所有 Role 转换为 RoleDTO
        userDTO.setRoles(user.getRoles().stream()
                .map(RoleDTO::fromRole)
                .collect(Collectors.toSet()));

        return userDTO;
    }

    public UserDTOV3(UUID id, String username, boolean status) {
        this.id = id;
        this.username = username;
        this.status = status;
    }

    // 构造方法
    public UserDTOV3(UUID id, String username, boolean status, Set<RoleDTO> roles) {
        this.id = id;
        this.username = username;
        this.status = status;
        this.roles = roles;
    }


}
